import type { Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import { ConfigEnv } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import OptimizationPersist from 'vite-plugin-optimize-persist'
import PkgConfig from 'vite-plugin-package-config'
import ViteRestart from 'vite-plugin-restart'
export default (env: ConfigEnv) => {
  const vitePlugins: (Plugin | Plugin[])[] = [
    vue({
      include: [/.vue$/],
    }),
    AutoImport({
      imports: ['vue', 'vue-router', 'pinia'],
      resolvers: [NaiveUiResolver()],
      dts: './src/auto-imports.d.ts',
      eslintrc: {
        enabled: true, // Default `false`
        filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
        globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
      },
    }),
    Components({
      dirs: ['src/components/'],
      extensions: ['vue'],
      resolvers: [NaiveUiResolver()],
      dts: './src/components.d.ts',
    }),
    ViteRestart({
      // 配置监听的文件
      restart: ['*.config.[jt]s', '**/config/*.[jt]s'], // ++
    }),
    PkgConfig(),
    OptimizationPersist(),
  ]
  return vitePlugins
}
